package com.hu.server.exception;

import com.baomidou.mybatisplus.extension.api.R;
import com.hu.server.pojo.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @Author qin
 * @Date 2021/12/26 19:31
 * @Version 1.0
 */
@RestControllerAdvice//控制器的增强类
public class GlobalException {

    @ExceptionHandler(SQLException.class)
    public RespBean mysqlException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException){
            return RespBean.error("数据库有关联,操作失败");
        }
        return RespBean.error("数据库异常,操作失败");
    }

}
